
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region PersonSearch Model -(by fangyifeng at 2007-09-14 12:24:15)

	/// <summary>
	/// PersonSearch object'PersonSearch'.
	/// </summary>
	[Serializable]
	public class PersonSearch : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _name;
		protected string _keyName;
		protected string _hobbies;
		protected string _giftType;
		protected string _giftPerson;
		protected string _giftOccasion;
		protected DateTime _createDate;
		protected string _beginPrice;
		protected string _endPrice;
		protected Customer _customer;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public PersonSearch() { }

		public PersonSearch( string name, string keyName, string hobbies, string giftType, string giftPerson, string giftOccasion, DateTime createDate, string beginPrice, string endPrice, Customer customer )
		{
			this._name = name;
			this._keyName = keyName;
			this._hobbies = hobbies;
			this._giftType = giftType;
			this._giftPerson = giftPerson;
			this._giftOccasion = giftOccasion;
			this._createDate = createDate;
			this._beginPrice = beginPrice;
			this._endPrice = endPrice;
			this._customer = customer;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public virtual string KeyName
		{
			get { return _keyName; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for KeyName", value, value.ToString());
				_keyName = value;
			}
		}

		public virtual string Hobbies
		{
			get { return _hobbies; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for Hobbies", value, value.ToString());
				_hobbies = value;
			}
		}

		public virtual string GiftType
		{
			get { return _giftType; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for GiftType", value, value.ToString());
				_giftType = value;
			}
		}

		public virtual string GiftPerson
		{
			get { return _giftPerson; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for GiftPerson", value, value.ToString());
				_giftPerson = value;
			}
		}

		public virtual string GiftOccasion
		{
			get { return _giftOccasion; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for GiftOccasion", value, value.ToString());
				_giftOccasion = value;
			}
		}

		public virtual DateTime CreateDate
		{
			get { return _createDate; }
			set { _createDate = value; }
		}

		public virtual string BeginPrice
		{
			get { return _beginPrice; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for BeginPrice", value, value.ToString());
				_beginPrice = value;
			}
		}

		public virtual string EndPrice
		{
			get { return _endPrice; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for EndPrice", value, value.ToString());
				_endPrice = value;
			}
		}

		public virtual Customer Customer
		{
			get { return _customer; }
			set { _customer = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is PersonSearch))
				throw new InvalidCastException("This object is not of type PersonSearch");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((PersonSearch)obj).Id);
					break;
				case "Name":
					relativeValue = this.Name.CompareTo(((PersonSearch)obj).Name);
					break;
				case "KeyName":
					relativeValue = this.KeyName.CompareTo(((PersonSearch)obj).KeyName);
					break;
				case "Hobbies":
					relativeValue = (this.Hobbies != null) ? this.Hobbies.CompareTo(((PersonSearch)obj).Hobbies) : -1;
					break;
				case "GiftType":
					relativeValue = (this.GiftType != null) ? this.GiftType.CompareTo(((PersonSearch)obj).GiftType) : -1;
					break;
				case "GiftPerson":
					relativeValue = (this.GiftPerson != null) ? this.GiftPerson.CompareTo(((PersonSearch)obj).GiftPerson) : -1;
					break;
				case "GiftOccasion":
					relativeValue = (this.GiftOccasion != null) ? this.GiftOccasion.CompareTo(((PersonSearch)obj).GiftOccasion) : -1;
					break;
				case "CreateDate":
					relativeValue = this.CreateDate.CompareTo(((PersonSearch)obj).CreateDate);
					break;
				case "BeginPrice":
					relativeValue = (this.BeginPrice != null) ? this.BeginPrice.CompareTo(((PersonSearch)obj).BeginPrice) : -1;
					break;
				case "EndPrice":
					relativeValue = (this.EndPrice != null) ? this.EndPrice.CompareTo(((PersonSearch)obj).EndPrice) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (PersonSearch.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
